//
//  YYAtmosphereCell.m
//  CollarMicrophone
//
//  Created by Yown on 2024/4/10.
//

#import "YYAtmosphereCell.h"

#import <BIToolModule/BIProjectDefine.h>
#import <BIProjectModule/BIAppDefine.h>

@interface YYAtmosphereCell ()

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIImageView *animationImageView;

@end

@implementation YYAtmosphereCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = [UIColor loadColorFromString:@"#FFFFFF"];
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 19;
    
    self.nameLabel.numberOfLines = 0;
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    self.nameLabel.textColor = [UIColor loadColorFromString:@"#333333"];
    self.nameLabel.font = BIFont(16);
    
    NSMutableArray *imageArray = [NSMutableArray array];
    for (NSUInteger i = 0; i < 40; i++) {
        NSString *imageName = [NSString stringWithFormat:@"atmosphere_sound%ld", i];
        UIImage *image = [UIImage imageNamed:imageName];
        [imageArray addObject:image];
    }
    self.animationImageView.animationImages = [imageArray copy];
    self.animationImageView.hidden = YES;
}

- (void)setupModel:(YYAtmosphereModel *)model {
    self.nameLabel.text = BILocalizedString(model.name);
    if (model.isPlay) {
        self.layer.borderWidth = 1.0;
        self.layer.borderColor = [UIColor loadColorFromString:@"#4CB49E"].CGColor;
        self.nameLabel.textColor = [UIColor loadColorFromString:@"#4CB49E"];
        self.animationImageView.hidden = NO;
        [self.animationImageView startAnimating];
    } else {
        self.layer.borderWidth = 0;
        self.layer.borderColor = [UIColor clearColor].CGColor;
        self.nameLabel.textColor = [UIColor loadColorFromString:@"#333333"];
        self.animationImageView.hidden = YES;
        [self.animationImageView stopAnimating];
    }
}

@end
